Public Class adm_uploadphoto
    Inherits System.Web.UI.Page
    'Protected WithEvents TheHeader1 As adm_header
    Public aUserSession(13) As String
    Public msg, imgpath, currtURL As String
    Dim bExit As Boolean
    Dim objdata As New gaValidation
    Public MerchantLogo As String
    Protected WithEvents lblStepOne As System.Web.UI.WebControls.Label
    Protected WithEvents CsvTypeButtonList As System.Web.UI.WebControls.RadioButtonList
    Protected WithEvents lblStepTwo As System.Web.UI.WebControls.Label
    Protected WithEvents lblError As System.Web.UI.WebControls.Label
    Protected WithEvents btnValidate As System.Web.UI.WebControls.Button
    Protected WithEvents inpFileUp As System.Web.UI.HtmlControls.HtmlInputFile
    Public MerchantBGImage As String
    Dim strSavePath As String
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TheHeader1.whichpage = 36
        'TheHeader1.pageid = "adduser"
        'TheHeader1.helpaid = ""
        'TheHeader1.iMenuLevel = 4
        'aUserSession = TheHeader1.security()
        'TheHeader1.StartInterface(36)
        objdata.getURL(Request.Url.ToString, imgpath, currtURL)
        'bExit = objdata.checkphoto()
        lblStepOne.CssClass = "tblhead"
        lblStepTwo.CssClass = "tblhead"
    End Sub
    'Public Function checkphoto() As Boolean
    '    msg = ""
    '    MerchantLogo = Trim(Request("MerchantLogo"))
    '    MerchantBGImage = Trim(Request("MerchantBGImage"))
    '    If Request("action") = "Cancel" Then
    '        Response.Redirect("mnu_system.asp")
    '    End If

    'oAdvconfig = Server.CreateObject("viaSystemSetup.SystemAdvanceConfig")
    'oAdvconfig.DBConnectstring = Application("DSN")
    'Rs = oAdvconfig.AdvancedConfig(aUserSession(cINVIDCONTEXT), pageid)
    'If Not Rs.EOF Then
    '    MerchantLogo = RS("merchant_logo")
    '    MerchantBGImage = RS("merchant_bgimage")
    '    RS.Close()
    '    RS = Nothing
    'End If

    'strLogoStatus = ""
    'strBGStatus = ""
    ''-----	checking for whether or not MerchantLogo exists.

    'If Len(Trim(MerchantLogo)) > 0 And Not isnull(Trim(MerchantLogo)) Then
    '    strLogoStatus = "<a href=""javascript:showimage('/images/upload/" & MerchantID & "/" & MerchantLogo & "')"">"
    '    strLogoStatus = strLogoStatus & MerchantLogo & "</a>"
    'Else
    '    strLogoStatus = "None found."
    'End If
    ''-----	checking for whether or not MerchantBGImage exists.
    'If Len(Trim(MerchantBGImage)) > 0 And Not isnull(Trim(MerchantBGImage)) Then
    '    strBGStatus = "<a href=""javascript:showimage('/images/upload/" & MerchantID & "/" & MerchantBGImage & "')"">"
    '    strBGStatus = strBGStatus & MerchantBGImage & "</a>"
    'Else
    '    strBGStatus = "None found."
    'End If

    'End Function

    Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click
        Dim strFilePrefix As String
        Dim strUploadPath As String = Server.MapPath("documents\adjustments\")
        Dim strFileName As String
        'Dim rightNow As DateTime = DateTime.Now
        'Dim FileDate As String 'create a string

        If CsvTypeButtonList.SelectedIndex >= 0 Then 'upload type selected
            If inpFileUp.Value <> "" Then 'file selected for upload
                If isCsvExt(inpFileUp.Value) = True Then 'file with *.csv being uploaded
                    strFilePrefix = CsvTypeButtonList.SelectedItem.Value
                    'FileDate = rightNow.ToString("MM_dd_yyyy")
                    'strFileName = strFilePrefix & FileDate & ".csv"
                    strFileName = strFilePrefix & UCase(Session("USER_ID")) & ".csv"
                    strSavePath = strUploadPath & strFileName
                    inpFileUp.PostedFile.SaveAs(strSavePath)
                    Response.Redirect("adj_check_csvfile.aspx?myPath=" & strSavePath & "&FilePrefix=" & strFilePrefix)
                End If
            Else
                lblStepTwo.CssClass = "subtitle2"
                lblError.Text = "<b>Problem:</b> Please select a file for uploading in <b>Step 2.</b> before proceeding."
            End If

        Else
            lblStepOne.CssClass = "subtitle2"
            lblError.Text = "<b>Problem:</b> Please select an adjustment type in <b>Step 1.</b> before proceeding."
        End If
    End Sub
    Private Function isCsvExt(ByVal strPath As String) As Boolean
        Dim arrPath As Array = Split(strPath, ".")
        Dim arrFile As Array = Split(strPath, "\")
        Dim strFileName As String = arrFile(arrFile.Length - 1)

        If LCase(arrPath(1)) <> "csv" Then
            lblStepTwo.CssClass = "subtitle2"
            lblError.Text = "<b>Problem:</b> The file selected for upload is not a valid adjustment file, it did not have a <b>csv</b> file extension."
            Return False
        Else
            Return True
        End If
    End Function

End Class
